package com.ly.mpayment.core.secuity;

import java.security.MessageDigest;

/*
 * MD5 算法
*/
public class MD5 {
 

	public static String md5(String str) {
		StringBuffer sb = new StringBuffer(32);
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			byte[] array = md.digest(str.getBytes("UTF-8"));
			for (int i = 0; i < array.length; i++) {
				sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).toLowerCase().substring(1, 3));
			}
		} catch (Exception e) {
			System.out.println("Can not encode the string '" + str + "' to MD5!");
			e.printStackTrace();
			return null;
		}
		return sb.toString();
	}
	 

	public static void main(String[] args) {
		/*
		 * System.out.println(MD5.GetMD5Code("123456"));
		 * System.out.println(MD5.GetMD5Code("654321"));
		 * System.out.println(MD5.GetMD5Code("353253"));
		 * System.out.println(MD5.GetMD5Code("981234"));
		 */
	}
}